package com.work.yshop.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 订单模型类
 */
public class Order implements Serializable {
    
    // 订单状态常量
    public static final int STATUS_PENDING = 1;      // 待付款
    public static final int STATUS_PROCESSING = 2;   // 待发货
    public static final int STATUS_SHIPPED = 3;      // 已发货
    public static final int STATUS_COMPLETED = 4;    // 已完成
    public static final int STATUS_CANCELED = 5;     // 已取消
    
    private String orderNumber;      // 订单编号
    private String buyerName;        // 买家姓名
    private String orderTime;        // 下单时间
    private double totalAmount;      // 订单总金额
    private int status;              // 订单状态
    private List<OrderItem> items;   // 订单项列表
    private String address;          // 收货地址
    private String phone;            // 联系电话
    
    public Order() {
        items = new ArrayList<>();
    }
    
    public Order(String orderNumber, String buyerName, String orderTime, double totalAmount, int status) {
        this.orderNumber = orderNumber;
        this.buyerName = buyerName;
        this.orderTime = orderTime;
        this.totalAmount = totalAmount;
        this.status = status;
        this.items = new ArrayList<>();
    }
    
    public String getOrderNumber() {
        return orderNumber;
    }
    
    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }
    
    public String getBuyerName() {
        return buyerName;
    }
    
    public void setBuyerName(String buyerName) {
        this.buyerName = buyerName;
    }
    
    public String getOrderTime() {
        return orderTime;
    }
    
    public void setOrderTime(String orderTime) {
        this.orderTime = orderTime;
    }
    
    public double getTotalAmount() {
        return totalAmount;
    }
    
    public void setTotalAmount(double totalAmount) {
        this.totalAmount = totalAmount;
    }
    
    public int getStatus() {
        return status;
    }
    
    public void setStatus(int status) {
        this.status = status;
    }
    
    public List<OrderItem> getItems() {
        return items;
    }
    
    public void setItems(List<OrderItem> items) {
        this.items = items;
    }
    
    public void addItem(OrderItem item) {
        if (items == null) {
            items = new ArrayList<>();
        }
        items.add(item);
    }
    
    public String getAddress() {
        return address;
    }
    
    public void setAddress(String address) {
        this.address = address;
    }
    
    public String getPhone() {
        return phone;
    }
    
    public void setPhone(String phone) {
        this.phone = phone;
    }
    
    /**
     * 获取订单状态文本
     */
    public String getStatusText() {
        switch (status) {
            case STATUS_PENDING:
                return "待付款";
            case STATUS_PROCESSING:
                return "待发货";
            case STATUS_SHIPPED:
                return "已发货";
            case STATUS_COMPLETED:
                return "已完成";
            case STATUS_CANCELED:
                return "已取消";
            default:
                return "未知状态";
        }
    }
    
    /**
     * 订单项类
     */
    public static class OrderItem implements Serializable {
        private int productId;       // 商品ID
        private String productName;  // 商品名称
        private double price;        // 商品单价
        private int quantity;        // 购买数量
        private String imageUrl;     // 商品图片URL
        
        public OrderItem() {
        }
        
        public OrderItem(int productId, String productName, double price, int quantity, String imageUrl) {
            this.productId = productId;
            this.productName = productName;
            this.price = price;
            this.quantity = quantity;
            this.imageUrl = imageUrl;
        }
        
        public int getProductId() {
            return productId;
        }
        
        public void setProductId(int productId) {
            this.productId = productId;
        }
        
        public String getProductName() {
            return productName;
        }
        
        public void setProductName(String productName) {
            this.productName = productName;
        }
        
        public double getPrice() {
            return price;
        }
        
        public void setPrice(double price) {
            this.price = price;
        }
        
        public int getQuantity() {
            return quantity;
        }
        
        public void setQuantity(int quantity) {
            this.quantity = quantity;
        }
        
        public String getImageUrl() {
            return imageUrl;
        }
        
        public void setImageUrl(String imageUrl) {
            this.imageUrl = imageUrl;
        }
        
        /**
         * 计算小计金额
         */
        public double getSubtotal() {
            return price * quantity;
        }
    }
} 